<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<%@ page import="com.scalar.chiptrack.utils.ConfigManager,
                 com.scalar.chiptrack.commons.Constants"%>

<chiptrack:checkLogon sourcePage="/priceSetting.do"/>

<HTML><HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor="#ffffff" leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">

<SCRIPT language="JavaScript">
    
    function GetAllProducts()
    {   
        newWindow = window.open('loadProducts.do','optionsPopup','channelmode=no,directories=no,toolbar=no,menubar=no,personalbar=no,status=no,scrollbars=yes,width=500,height=600,left=300,top=30,resizable=no');
  	//newWindow.moveTo(300,30);
  	newWindow.focus();
    }
    function cancelAndGoBack() {
            document.location = '<%=chipTracContext%>/priceSetting.do?action=customerPricing';
    }
    //Added by varma(30jun 2004)
    function assignProduct(passedValue)
    {
	document.priceForm.productId.value = passedValue;
	window.focus();
    }

    function updatePrices()
    {
		var temp = document.priceForm;
		var pa = document.getElementById ("errors");
		var fromVal = new Array(temp.fromQty.length);
		var toVal = new Array(temp.fromQty.length);
		var message ='';

		xyz:
		for( var x=0 ; x < temp.fromQty.length ; x++)
		{
			document.priceForm.fromQty[x].value = document.priceForm.fromQty[x].value.trim();
			document.priceForm.toQty[x].value = document.priceForm.toQty[x].value.trim();

			if ( document.priceForm.fromQty[x].value != null && document.priceForm.toQty[x].value != null && document.priceForm.fromQty[x].value != '' && document.priceForm.toQty[x].value != '' )
			{
				// TO CHECK FOR VALID INTEGERS
				if( checkInteger( document.priceForm.fromQty[x].value , "From Quantity" ,"N")  == false)
				{
					document.priceForm.fromQty[x].focus();
					message = errMsg;
					break xyz;
				}
				if( checkInteger( document.priceForm.toQty[x].value , "To Quantity" ,"N")  == false )
				{
					document.priceForm.toQty[x].focus();
					message = errMsg;
					break xyz;
				}

				// TO CHECK WETHER FROM QTY GREATER THEN TO QTY
				if ( parseInt(temp.fromQty[x].value ) >= parseInt(temp.toQty[x].value) )
				{
					message = "'To quantity 'cannot be less then or equal to' From quantity'";
					document.priceForm.toQty[x].focus();
					break xyz;
				}
				else
				{
					fromVal[x] = temp.fromQty[x].value;
					toVal[x] = temp.toQty[x].value;
				}
			}
			else
			{
				if( document.priceForm.fromQty[x].value != '' )
				{
					message = "To Quantity must be given if From quantity is given";
					document.priceForm.toQty[x].focus();
					break xyz;
				}

				if( document.priceForm.toQty[x].value != '' )
				{
					message = "From Quantity must be given if To quantity is given";
					document.priceForm.fromQty[x].focus();
					break xyz;
				}
			}
		}

		if( message != ''  )
		{
			pa.innerHTML = message;
			return;
		}

		xyz1:
		for (var y = 1 ; y < fromVal.length ; y++ )
		{
			//for( var a = 0 ; a < fromVal.length ; a++  )
			for( var a = y-1 ; a >= 0 ; a--  )
			{
				if( y != a  && temp.fromQty[y].value != '' && temp.fromQty[a].value != '' &&  temp.fromQty[a].value != '')
				{
					//alert("y  "+parseInt(temp.fromQty[y].value ) +" a " + parseInt(temp.fromQty[a].value));
					//alert("y  "+parseInt(temp.fromQty[y].value ) +" a " + parseInt(temp.toQty[a].value));
					if( parseInt(temp.fromQty[y].value ) >= parseInt(temp.fromQty[a].value ) &&  parseInt(temp.fromQty[y].value ) <= parseInt(temp.toQty[a].value ))
					{
						temp.fromQty[y].focus();
						message = "Please define a valid range";
						break xyz1;
					}

					if( parseInt(temp.toQty[y].value ) >= parseInt(temp.fromQty[a].value ) &&  parseInt(temp.toQty[y].value ) <= parseInt(temp.toQty[a].value ))
					{
						temp.toQty[y].focus();
						message = "Please define a valid range";
						break xyz1;
					}
				}
			}
		}

		if( message != ''  )
		{
			pa.innerHTML = message;
			return;
		}

        document.priceForm.action.value = "UpdateCustomerPricing";
        document.priceForm.submit();
    }

    function loadPrice()
    {
        var pa = document.getElementById ("errors");

        if ( document.priceForm.productId.value == '' || document.priceForm.productId.value == '-1' || document.priceForm.productId.value == '0')
        {
            pa.innerHTML = "<li>Please select a product to set the price</li>";
			return;
        }

        var selVal = document.priceForm.productId.selectedIndex;

        document.priceForm.action.value = "loadCustomerPricing";
        document.priceForm.mktpartNo.value = document.priceForm.productId.options[selVal].text;
        document.priceForm.submit();
    }

    if (document.layers)
        window.setResizable(false);

   function addTextBoxes()
   {
        var htmltext = '<div><table border="0" width="100%"><tr><td width="30%" class="NArialL">';
        htmltext = htmltext + '<input type="text" name="fromQty" class="valuetxfield"></td>';
        htmltext = htmltext + '<td width="30%" align="left" class="NArialL"> <input type="text" name="toQty" class="valuetxfield"> </td>';
        htmltext = htmltext + '<td width="30%" class="NArialL"><input type="text" value="0.0" name="price" class="valuetxfield" maxlength="9" onkeypress="javascript:restrictCharacters(this,7,2)" onkeyup="javascript:restrictAmt(this,7,2)"/></td>';
        var pa=document.getElementById("font1");
        pa.insertAdjacentHTML('BeforeEnd',htmltext);
    }

</SCRIPT>
<script src="<%=chipTracContext%>/jsp/includes/scripts/functions.js"></script>
<script src="<%=chipTracContext%>/jsp/includes/scripts/validations.js"></script>


<!-- Top Header Start-->

<%@ include file="/jsp/includes/header.jsp" %>

<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
	<td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

<!-- Side Navigation start -->
    
<%@ include file="/jsp/marketing/price_setting_menu.jsp" %>

</TD>
<!-- end of the side navigations -->
<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
<TD valign="top" width="100%">

<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR>
<!-- from here your body starts -->
<center><span class="NArialW">Customer Pricing</span></center>
<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10>
<html:form name="priceForm" action="/priceSetting.do" method="post" type="com.scalar.chiptrack.marketing.PricingForm">
<table border="0" width="85%" align=right>
    <logic:equal name="showMessage" value="TRUE">
        <tr><td colspan="3" align='left'><font class='NArialS'color='blue'><b><%=Constants.NO_MODIFY_RIGHTS %></b></font></td></tr>
    </logic:equal>
    <tr><td colspan='3'><font class="NArialL"><font color="FF0000"><FONT id="errors"></FONT></FONT></FONT></TD></TR>
    <tr><td colspan='3' align="left"><chiptrack:errors styleClass="NArialL" /></td></tr>
    <tr><td colspan='3' align="left"><chiptrack:info styleClass="NArialL" /></td></tr>
    <logic:equal name="showList" value="FALSE">
    <tr>
        <td width="15%" colspan='1'>&nbsp;</td>
        <td class='NArialL' width="25%"><font class="NArialL">Product Name :<font size="-2"> <br>(<bean:message key="label.mfgPartNumber" />)</font></font></td>
        <td width="60%" class="NArialL">
            <html:select property="productId" styleClass="txfield">
            <html:option value="-1">--Select Product Name--</html:option>
            <html:options collection="mktgParts" property="value" labelProperty="label"/>
            </html:select>
        </td>
    </tr>
    <tr>
        <td width="15%" colspan='1'>&nbsp;</td>
        <td class='NArialL' width="25%">Customer Name: </td>
        <td width="60%">
            <html:select name="priceForm" property="customerId" styleClass="txfield">
                <html:options collection="customers" property="value" labelProperty="label"/>
            </html:select>
        </td>
    </tr>
    <tr>
         <td width="15%" colspan='1'>&nbsp;</td>
         <td class='NArialL' width="25%">Sales Order Type :</td>
      	 <td width="60%" class="NArialL">
            <html:select  property="sample" styleClass="txfield">
			    <html:option value="1">Regular</html:option>
                <html:option value="0">Sample</html:option>
            </html:select>
          </td>
    </tr>
    <tr><td colspan=3><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>
    <tr>
        <td colspan=3 align="center">
            <a href="javascript:loadPrice();"><img src="<%=chipTracContext%>/jsp/includes/images/search.gif" border=0 onmouseover="window.status='Click to Search for Prices';return true" onmouseout="window.status='';return true"title="Click here to Search for prices"></a>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <a href="javascript:document.priceForm.reset();"><img src="<%=chipTracContext%>/jsp/includes/images/reset.gif" border=0 onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true"title="Click here to Reset"></a>
        </td>
    </tr>
    </logic:equal>
    <logic:equal name="showList" value="TRUE">
    <tr>
        <td colspan='3' align="left" class='NArialL'>Price setting for marketing part # <font color="blue"><%=request.getParameter("mktpartNo")%></font></td>
    </tr>
    <tr>
        <td width='50%' colspan='3' align="left" class="NArialL"> Customer Name : <font color="blue"><bean:write name="priceForm" property="customerName" /></td>
    </tr>
   <logic:equal value="0" name="priceForm" property="sample" >
        <tr><td colspan='3' align="left" class='NArialL'>For  <font color="blue"> Sample </font> Sales Order   </td></tr>
     </logic:equal>
    <logic:equal value="1" name="priceForm" property="sample">
        <tr><td colspan='3' align="left" class='NArialL'>For  <font color="blue"> Regular </font> Sales Order   </td></tr>
    </logic:equal>
     
    <html:hidden name="priceForm" property="productId" />
    <html:hidden name="priceForm" property="customerId" />
    <html:hidden name="priceForm" property="sample" />
    <%-- Commented by Krishna Prasad on 08 May 2004, errors and info message not displaying after the saving or updating of records
    <tr><td colspan='3' align="left"><chiptrack:errors styleClass="NArialL" /></td></tr>
    <tr><td colspan='3' align="left"><chiptrack:info styleClass="NArialL" /></td></tr>  --%>

    <tr>
        <td width='60%' class="NArialL" colspan='2' align="center" bgcolor="#993333">
                <font color="#FFFFFF">Quantities</font></td>
        <td width='30%' class="NArialL" rowspan='2' align="center" bgcolor="#993333"><font color="#FFFFFF">Price</font></td>
    </tr>
    <tr>
        <td width='30%' class="NArialL" align="center" bgcolor="#993333"><font color="#FFFFFF"> From </font></td>
        <td width='30%' class="NArialL" align="center" bgcolor="#993333"><font color="#FFFFFF"> To </font></td>
        <td width='30%'></td>
     </tr>
     <logic:notEmpty name="priceForm" property="priceList">
     <logic:iterate id="Pricing" name="priceForm" property="priceList">
     <tr>
        <td width='30%' class="NArialL"> <html:text name="Pricing" property="fromQty" styleClass="valuetxfield" /> </td>
        <td width='30%' class="NArialL"> <html:text name="Pricing" property="toQty" styleClass="valuetxfield" /> </td>
        <td width='30%' class="NArialL"><html:text name="Pricing" property="price" styleClass="valuetxfield" maxlength="9" onkeypress="javascript:restrictCharacters(this,7,2)" onkeyup="javascript:restrictAmt(this,7,2)"  /></td>
     </tr>
     </logic:iterate>	
    <tr><td colspan=3><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>    
    </logic:notEmpty>
     <logic:iterate id="Pricing" name="newList">
     <tr>
        <td width='30%' class="NArialL"> <html:text name="Pricing" property="fromQty" styleClass="valuetxfield" /> </td>
        <td width='30%' class="NArialL"> <html:text name="Pricing" property="toQty" styleClass="valuetxfield" /> </td>
        <td width='30%' class="NArialL"><html:text name="Pricing" property="price" styleClass="valuetxfield" maxlength="9" onkeypress="javascript:restrictCharacters(this,7,2)" onkeyup="javascript:restrictAmt(this,7,2)" /></td>
     </tr>
     </logic:iterate>	
    <tr><td colspan=3><FONT id="font1"></FONT></TD></TR>
    <tr><td colspan=3><a href='javascript:addTextBoxes();'><IMG src='<%=chipTracContext%>/jsp/includes/images/addmore.gif' border=0 onmouseover="window.status='Click to Add More Text Boxes';return true" onmouseout="window.status='';return true"title="Click here to Add More Text Boxes"></a></td></tr>
    <tr><td colspan=3><img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20></td></tr>
    <tr>
      <td colspan=2 align=center>
        <chiptrack:restrictedLink functionality='<%=Functionality.MARKETING_CUSTOMER_PRICING %>' action='<%=User.USER_ACTION_MODIFY%>' href='javascript:updatePrices();' onmouseover="window.status='Click to Update Prices';return true" onmouseout="window.status='';return true">
            <img border="0" src="<%=chipTracContext%>/jsp/includes/images/submit.gif" title="Click here to Update Prices"/>
        </chiptrack:restrictedLink>
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <a href="javascript:document.priceForm.reset();"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17"  onmouseover="window.status='Click to Reset';return true" onmouseout="window.status='';return true"title="Click here to Reset"></a>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <%--Modified by varma(30 jun 2004) --%>
      <%--<a href="#" onclick="window.history.back();"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif" width="53" height="17"  onmouseover="window.status='Click to Cancel ';return true" onmouseout="window.status='';return true"title="Click here to Cancel"></a> --%>
      <a href="javascript:cancelAndGoBack();"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/cancel.gif" width="53" height="17"  onmouseover="window.status='Click to Cancel ';return true" onmouseout="window.status='';return true"title="Click here to Cancel"></a>
        </td>
    </tr>
    </logic:equal>
  </table>
<input type="hidden" name="action" value="">
<input type="hidden" name= "mktpartNo" value ="<%=request.getParameter("mktpartNo")%>">
</html:form>
<!-- till here -->
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>
<!-- Footer starts here -->

<%@ include file="/jsp/includes/footer.jsp" %>

<!-- footer end here -->

</BODY>
</HTML>
